<script setup>
import { introApi } from "@/services/index";
import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
import { nextTick, ref, watch, onMounted } from "vue";
import { messageQuery } from "@/services/user";

const form = ref({
  pageIndex: 1,
  pageSize: 20,

  keyword: "",
});
const productData = ref([]);

const loading = ref("");
const getDateLst = async (index) => {
  if (index == 1) {
    productData.value = [];
    loading.value = "";
  }
  if (index) {
    form.value.pageIndex = index;
  }
  if (loading.value == "noMore") {
    return;
  }
  loading.value = "Loading";
  try {
    let res = await messageQuery(form.value);
    if (res.code == 200) {
      productData.value = productData.value.concat(res.data.datas);

      form.value.pageIndex = form.value.pageIndex + 1;
      if (res.data.datas.length < form.value.pageSize) {
        loading.value = "noMore";
      } else {
        loading.value = "More";
      }
    } else {
    }
    // console.log(res);
  } catch (e) {}
};
onLoad((e) => {
  // getDateLst();
});
onShow(() => {
  getDateLst();
});
onReachBottom(() => {
  getDateLst();
});

const goNews = (item) => {
  uni.navigateTo({
    url: `/pages/users/newsDet/index?id=${item.id}`,
  });
};
</script>

<template>
  <top-nav :title="'消息通知'" :border="false" rType="save"></top-nav>

  <view class="content">
    <view
      class="item"
      v-for="(item, index) in productData"
      :key="index"
      @click="goNews(item)"
    >
      <view class="title"
        >{{ item.title }}<text v-if="!item.readed"></text>
      </view>
      <view class="des">{{ item.createTime }}</view>

      <view class="info">
        <!-- <view>单据编号：788284324</view>
        <view>调出：7</view>
        <view>调入：7</view>
        <view>件数：7</view>
        <view>总价：7</view> -->

        <view class="see">点击查看单据>></view>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
@import "index.scss";
</style>
